<?php

namespace App\Http\Controllers;

use App\Category;
use App\Exceptions\ValidatorException;
use App\Http\Response;
use App\Repository\CategoryRepository;
use Illuminate\Http\Request;

class CategoryController extends Controller
{
    protected $repository;

    public function __construct()
    {
        $this->repository = new CategoryRepository();
    }

    /**
     * Display a listing of the resource.
     *
     * @return Response
     */
    public function index(Request $request)
    {
        $type = $request->input('type', 0);
        return Response::success($this->repository->index($type));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @throws ValidatorException
     * @return Response
     */
    public function store(Request $request)
    {
        return Response::success($this->repository->store($request->input()));
    }

    /**
     * Display the specified resource.
     *
     * @param  \App\Category  $category
     * @return \Illuminate\Http\Response
     */
    public function show(Category $category)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  \App\Category  $category
     * @return \Illuminate\Http\Response
     */
    public function edit(Category $category)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Category  $category
     * @return Response
     */
    public function update(Request $request, Category $category)
    {
        return Response::success($this->repository->update($request->input(), $category));
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  \App\Category  $category
     * @return Response
     */
    public function destroy(Category $category)
    {
        return Response::success($this->repository->destroy($category));
    }

    public function withContent(Request $request)
    {
        return Response::success($this->repository->content($request));
    }
}
